<template>
  <div class="app-container">
    <h1>用户管理</h1>
    <div class="content">
      <el-card>
        <el-form :inline="true" :model="queryParams" ref="queryForm" class="search-form">
          <el-form-item label="用户名称" prop="userName">
            <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable />
          </el-form-item>
          <el-form-item label="手机号码" prop="phonenumber">
            <el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="用户状态" clearable>
              <el-option label="正常" value="0" />
              <el-option label="停用" value="1" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="Edit">修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="Delete">删除</el-button>
          </el-col>
        </el-row>

        <el-table :data="userList" border>
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="用户编号" prop="userId" width="100" />
          <el-table-column label="用户名称" prop="userName" :show-overflow-tooltip="true" />
          <el-table-column label="用户昵称" prop="nickName" :show-overflow-tooltip="true" />
          <el-table-column label="部门" prop="deptName" :show-overflow-tooltip="true" />
          <el-table-column label="手机号码" prop="phonenumber" width="120" />
          <el-table-column label="状态" align="center" width="100">
            <template #default="scope">
              <el-switch v-model="scope.row.status" active-value="0" inactive-value="1" />
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" prop="createTime" width="160" />
          <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width">
            <template #default="scope">
              <el-button type="text" icon="Edit" @click="handleUpdate(scope.row)">修改</el-button>
              <el-button type="text" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'

// 查询参数
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  userName: '',
  phonenumber: '',
  status: ''
})

// 用户列表数据
const userList = ref([
  { userId: 1, userName: 'admin', nickName: '管理员', deptName: '研发部门', phonenumber: '13800138000', status: '0', createTime: '2023-01-01' },
  { userId: 2, userName: 'test', nickName: '测试用户', deptName: '测试部门', phonenumber: '13800138001', status: '0', createTime: '2023-01-02' }
])

// 总条数
const total = ref(2)

// 查询用户列表
const getList = () => {
  // 实际项目中应该调用API获取数据
  console.log('获取用户列表', queryParams)
}

// 搜索按钮操作
const handleQuery = () => {
  queryParams.pageNum = 1
  getList()
}

// 重置按钮操作
const resetQuery = () => {
  queryParams.userName = ''
  queryParams.phonenumber = ''
  queryParams.status = ''
  handleQuery()
}

// 修改按钮操作
const handleUpdate = (row) => {
  console.log('修改用户', row)
}

// 删除按钮操作
const handleDelete = (row) => {
  console.log('删除用户', row)
}

onMounted(() => {
  getList()
})
</script>

<style scoped>
.content {
  padding: 20px;
  font-size: 16px;
}
.search-form {
  margin-bottom: 20px;
}
.mb8 {
  margin-bottom: 8px;
}
</style>
